package com.guochenglang.www.controller;

import com.guochenglang.www.service.LikesService;
import com.guochenglang.www.util.GetObject;
import com.guochenglang.www.util.MyDependency;
import com.guochenglang.www.web.result.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 点赞Controller层
 *
 * @author GuoChenglang
 */

public class LikesController {
    private static final LikesService LIKES_SERVICE = MyDependency.returnObject(LikesService.class);

    public static Result clickLikes(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, InterruptedException, IllegalAccessException, InstantiationException {
        //获得点赞人id
        Integer likeId = GetObject.getValue(request, Integer.class, "likeId");
        //获得文章id
        Integer articleId = GetObject.getValue(request, Integer.class, "articleId");
        //添加进点赞表
        return Result.result(LIKES_SERVICE.clickLikes(likeId, articleId));
    }

    /**
     * 获得点赞数
     */
    public static Result getLikes(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, InterruptedException, IllegalAccessException, InstantiationException {
        //获得文章id
        int articleId = GetObject.getObject(request, Integer.class);
        return Result.result(LIKES_SERVICE.getLikes(articleId));
    }
}
